package vossenenkonijnen;

import java.util.List;

import controller.Field;

/**
 * Class holds grass for simulation.
 * Not used for this project simulation.
 * @author Projectgroep 5
 *
 */
public class Grass implements Actor 
{
	private boolean active;
    private Field field;
    private Location location;
    
    /**
     * Create new grass
     * @param field
     * @param location
     */
	public Grass(Field field, Location location) 
	{
		active = true;
        this.field = field;
        setLocation(location);
	}

	@Override
	public void act(List<Actor> newActors) 
	{
		if(isActive()) 
		{
            Location location = getLocation();
            
            Location newLocation = getField().randomAdjacentLocation(location);
            
            // See if it was possible to move.
            /*if(newLocation != null) 
            {
                setLocation(newLocation);
            }
            */Field field = getField();
            new Grass(field, newLocation);
            /*List<Location> free = field.getFreeAdjacentLocations(getLocation());
            for(int b = 0; free.size() > 0; b++) {
                Location loc = free.remove(0);
                	Grass young = new Grass(field, field.getFreeAdjacentLocations(getLocation()));
                }*/
		}                   
	}

	@Override
	public boolean isActive() 
	{
		return active;
	}
	
	/**
     * Place the animal at the new location in the given field.
     * @param newLocation The animal's new location.
     */
    public void setLocation(Location newLocation)
    {
        if(location != null) {
            //field.clear(location);
        }
        location = newLocation;
        //field.place(this, newLocation);
    }
    
    /**
     * Return the animal's location.
     * @return The animal's location.
     */
    public Location getLocation()
    {
        return location;
    }
    
    /**
     * Return the animal's field.
     * @return The animal's field.
     */
    public Field getField()
    {
        return field;
    }
    
    /**
     * Indicate that the animal is no longer alive.
     * It is removed from the field.
     */
    public void setDead()
    {
        active = false;
        if(location != null) {
            field.clear(location);
            location = null;
            field = null;
        }
    }

}
